package com.lanou3g.mynewstest.module.news.headline;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.lanou3g.mynewstest.R;
import com.lanou3g.mynewstest.beans.NewsHeadlineBeans;
import com.lanou3g.mynewstest.beans.NewsPhotoSetBeans;
import com.lanou3g.mynewstest.tools.MyRequestQueue;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/15.
 */
public class PhotoSetAdapter extends PagerAdapter {
    private Context context;
    private NewsPhotoSetBeans data;

    public PhotoSetAdapter(Context context, NewsPhotoSetBeans data) {
        this.context = context;
        this.data = data;
    }
    @Override
    public int getCount() {
        return data.getPhotos().size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_photoset, null);
        TextView note, page, title;
        NetworkImageView imageView;
        note = (TextView) view.findViewById(R.id.item_photoset_note);
        page = (TextView) view.findViewById(R.id.item_photoset_page);
        title = (TextView) view.findViewById(R.id.item_photoset_title);
        imageView = (NetworkImageView) view.findViewById(R.id.item_photoset_iv);
        title.setText(data.getSetname());
        page.setText((position + 1) + "/" + data.getPhotos().size());
        note.setText(data.getPhotos().get(position).getNote());
        MyRequestQueue.setNetImage(imageView, data.getPhotos().get(position).getImgurl());
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
